package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.RoomType;
import com.zzyl.nursing.service.IRoomTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房型Controller
 *
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/elder/roomType" )
@Tag(name = "房型相关接口" )
public class RoomTypeController extends BaseController {
    @Autowired
    private IRoomTypeService roomTypeService;

    /**
     * 查询房型列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:type:list')" )
    @GetMapping("/list" )
    @Operation(summary = "查询房型列表" )
    public TableDataInfo list(RoomType roomType) {
        startPage();
        List<RoomType> list = roomTypeService.selectRoomTypeList(roomType);
        return getDataTable(list);
    }

    /**
     * 导出房型列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:type:export')" )
    @Log(title = "房型" , businessType = BusinessType.EXPORT)
    @Operation(summary = "导出房型列表" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, RoomType roomType) {
        List<RoomType> list = roomTypeService.selectRoomTypeList(roomType);
        ExcelUtil<RoomType> util = new ExcelUtil<RoomType>(RoomType.class);
        util.exportExcel(response, list, "房型数据" );
    }

    /**
     * 获取房型详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:type:query')" )
    @GetMapping("/{id}" )
    @Operation(summary = "获取房型详细信息" )
    public R<RoomType> getInfo(@Schema(title = "房型ID" )
                               @PathVariable("id" ) Long id) {
        return R.ok(roomTypeService.selectRoomTypeById(id));
    }

    /**
     * 新增房型
     */
    @PreAuthorize("@ss.hasPermi('nursing:type:add')" )
    @Log(title = "房型" , businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增房型" )
    public AjaxResult add(@Schema(title = "房型实体" ) @RequestBody RoomType roomType) {
        return toAjax(roomTypeService.insertRoomType(roomType));
    }

    /**
     * 修改房型
     */
    @PreAuthorize("@ss.hasPermi('nursing:type:edit')" )
    @Log(title = "房型" , businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改房型" )
    public AjaxResult edit(@Schema(title = "房型实体" ) @RequestBody RoomType roomType) {
        return toAjax(roomTypeService.updateRoomType(roomType));
    }

    /**
     * 删除房型
     */
    @PreAuthorize("@ss.hasPermi('nursing:type:remove')" )
    @Log(title = "房型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @Operation(summary = "删除房型" )
    public AjaxResult remove(@Schema(title = "房型ID数组" ) @PathVariable Long[] ids) {
        return toAjax(roomTypeService.deleteRoomTypeByIds(ids));
    }
}
